<template>
  <div class="wrap">
    <div class="job-page">
      <!-- 顶部导航栏 -->
      <header class="page-header">
        <div class="top">
          <van-dropdown-menu>
            <van-dropdown-item v-model="location" :options="locationOptions" />
          </van-dropdown-menu>
          <div class="input">
            <van-search
              v-model="searchKeyword"
              placeholder="搜索职位/公司"
              shape="round"
              @search="onSearch"
            />
          </div>
        </div>

        <!-- 轮播图 -->
        <div class="swiper">
          <van-swipe :autoplay="3000" lazy-render>
            <van-swipe-item v-for="(image, index) in images" :key="index">
              <img :src="image" />
            </van-swipe-item>
          </van-swipe>
        </div>
      </header>

      <!-- 标签页 -->
      <div class="tab-section">
        <div class="tab-header">
          <span
            v-for="(tab, index) in tabs"
            :key="index"
            :class="{ active: activeTab === index }"
            @click="switchTab(index)"
          >
            {{ tab }}
          </span>
        </div>
        <div class="tab-indicator">
          <span :class="{ active: activeTab === 0 }"></span>
          <span :class="{ active: activeTab === 1 }"></span>
        </div>
      </div>

      <!-- 静态职位列表 -->
      <div class="job-list" v-for="(item, index) in jobList" :key="index">
        <!-- 职位卡片1 -->
        <div class="job-card" @click="goToJobDetail(item._id)">
          <div class="job-title">{{ item.title }}</div>
          <div class="job-meta">
            <span>{{ item.workAddress }}</span
            ><span>|</span><span>{{ item.workRange }}年</span><span>|</span
            ><span>{{ item.education }}</span>
          </div>
          <div class="job-tags">
            <span v-for="ele in item.welfare" :key="ele">{{ ele }}</span>
          </div>
          <div class="company-info">
            <span class="company-name">{{ item.companyInfo[0].title }}</span>
            <span class="company-tags">
              <span>{{ item.companyInfo[0].companyType }}</span
              ><span>{{ item.companyInfo[0].companyNumber }}人</span>
            </span>
          </div>
          <div class="job-salary">{{ item.salary }}K</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { getCitesList, getJobsList } from "../../api/home";
const router = useRouter();

// 轮播图数据
const images = [
  "https://mina.52kfw.cn/uploads/attach/2022/06/20220613/745f4d285c8499a83c30ea7483380660.jpg",
  "https://mina.52kfw.cn/uploads/attach/2022/06/20220613/d5c0d51da2372060959d5739fe445e42.jpg",
  "https://mina.52kfw.cn/uploads/attach/2022/06/20220613/8392235884f2f3e51cc0a8f9a1c5d5f4.jpg",
];

// 城市选择
const location = ref("北京");
const locationOptions = ref([]);
const jobList = ref([]);
const getCity = async () => {
  let res = await getCitesList();
  console.log(res);
  locationOptions.value = res.data.map((item) => ({
    text: item,
    value: item,
  }));
};
getCity();

const getJobList = async () => {
  let res = await getJobsList();
  console.log(res);
  jobList.value = res.data.list;
};
getJobList();
// 搜索功能
const searchKeyword = ref("");
const onSearch = () => {
  console.log("搜索关键词:", searchKeyword.value);
  // 这里可以添加搜索逻辑
};

// 标签页
const tabs = ["推荐", "最新"];
const activeTab = ref(0);
const switchTab = (index) => {
  activeTab.value = index;
  // 这里可以添加标签切换逻辑
};

// 跳转到职位详情
const goToJobDetail = (id) => {
  router.push({
    path: "/detail",
    query: {
      id,
    },
  });
};
</script>

<style scoped>
.wrap {
  height: 100vh;
  background-color: #f5f5f5;
}

.job-page {
  font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: #333;
  padding-bottom: 50px;
}

.page-header {
  background-color: #149639;
  /* padding-bottom: 10px; */
}

.top {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 12px;
}

:deep(.van-dropdown-menu) {
  width: 80px;
  background-color: transparent;
  height: 40px;
}

:deep(.van-dropdown-menu__item) {
  background-color: #149639;
}

:deep(.van-dropdown-menu__title) {
  color: #fff;
  font-size: 14px;
}

:deep(.van-dropdown-menu__title::after) {
  border-color: #fff;
}

.input {
  flex: 1;
  margin-left: 10px;
}

:deep(.van-search) {
  padding: 0;
}

:deep(.van-search__content) {
  background-color: #fff;
}

/* 全屏宽度轮播图 */
.swiper {
  margin: 0;
  border-radius: 0;
  overflow: hidden;
}

.swiper img {
  width: 100%;
  /* height: 120px; */
  object-fit: cover;
  display: block;
}

.tab-section {
  margin: 20px 0;
  background-color: #fff;
  padding: 10px 0;
}

.tab-header {
  display: flex;
  justify-content: center;
  gap: 30px;
  font-size: 16px;
  font-weight: 500;
}

.tab-header span {
  padding: 5px 0;
  color: #666;
  cursor: pointer;
}

.tab-header span.active {
  color: #149639;
  font-weight: bold;
}

.tab-indicator {
  text-align: center;
  margin-top: 8px;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.tab-indicator span {
  display: inline-block;
  width: 20px;
  height: 3px;
  background-color: #eee;
  border-radius: 2px;
}

.tab-indicator span.active {
  background-color: #149639;
}

.job-list {
  margin-bottom: 60px;
  padding: 0 12px;
}

.job-card {
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  background-color: #fff;
  position: relative;
}

.job-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  padding-right: 80px;
}

.job-meta {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
}

.job-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.job-tags span {
  font-size: 12px;
  padding: 4px 8px;
  background-color: #f5f5f5;
  border-radius: 4px;
  color: #666;
}

.company-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.company-name {
  font-size: 14px;
  font-weight: 500;
}

.company-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: #999;
}

.company-tags span {
  display: inline-block;
}

.job-salary {
  position: absolute;
  right: 16px;
  top: 16px;
  color: #ff6b00;
  font-weight: bold;
  font-size: 16px;
}
</style>
